// ++++++++++++++++++++++++++++++++++++++++
// 《Go 语言+Vue.js 实战派——基于 Gin 框架》源码
// ++++++++++++++++++++++++++++++++++++++++
// 作者公众号：源码大数据
// 自媒体账号（抖音、视频号、快手、B站、知乎）：廖显东-ShirDon
// 仓库地址：https://gitee.com/shirdonl/goGinVue.git
// 仓库地址：https://github.com/shirdonl/goGinVue.git
// // 博客：https://www.shirdon.com
// 购买图书：https: //item.jd.com/14958064.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"strings"
)

func main() {
	r := gin.Default()
	r.GET("/hi", func(c *gin.Context) {
		c.String(http.StatusOK, "Hi, this is test route")
	})

	r.GET("/customers/:name", func(c *gin.Context) {
		name := c.Param("name")
		c.String(http.StatusOK, "Hi, %s", name)
	})

	api := r.Group("/group_api")
	{
		api.GET("/customers", func(c *gin.Context) {
			//处理 GET 请求以获取所有用户
		})

		api.POST("/customers", func(c *gin.Context) {
			// 处理 POST 请求以创建新用户
		})
	}

	r.Handle("GET", "/*filepath", func(c *gin.Context) {
		if strings.HasSuffix(c.Param("filepath"), ".html") {
			c.String(http.StatusOK, "HTML file requested: %s", c.Param("filepath"))
		} else {
			c.String(http.StatusNotFound, "Invalid file requested")
		}
	})

	r.Run(":8080")
}
